/**
* 左边菜单
*/
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#637085" text-color="#fff" active-text-color="#66b1ff">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span>{{menu.menuname}}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
          <i class="iconfont" :class="chmenu.icon"></i>
          <span>{{chmenu.menuname}}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>
import {mapGetters} from "vuex";
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: []
    }
  },
  computed: {
    ...mapGetters(['roleInfo'])
  },
  // 创建完毕状态(里面是操作)
  async created() {
    // 静态左侧菜单栏
    let res = {
      success: true,
      data: [
        {
          menuid: 102,
          icon: 'icon-yijianfankui',
          menuname: '客户咨询管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 103,
              icon: 'icon-shuju-xiaofeizhejiaoyidingdan',
              menuname: '反馈列表',
              hasThird: 'N',
              url: 'feedback/feedbackList',
              menus: null
            },
            {
              menuid: 104,
              icon: 'icon-jishunantijiejue',
              menuname: '技术反馈列表',
              hasThird: 'N',
              url: 'feedback/technicalFeedbackeedback',
              menus: null
            },
            // {
            //   menuid: 104,
            //   icon: 'icon-banben',
            //   menuname: '详情',
            //   hasThird: 'N',
            //   url: 'feedback/feedbackDetail',
            //   menus: null
            // },
            {
              menuid: 105,
              icon: 'icon-shujumokuai',
              menuname: '模块列表',
              hasThird: 'N',
              url: 'feedback/moduleList',
              menus: null
            },
            {
              menuid: 106,
              icon: 'icon-changjianwenti',
              menuname: '常见问题',
              hasThird: 'N',
              url: 'feedback/problemList',
              menus: null
            },
            {
              menuid: 107,
              icon: 'icon-wentidan',
              menuname: '问题日志',
              hasThird: 'N',
              url: 'feedback/problemLog',
              menus: null
            },
          ]
        },
        {
          menuid: 111,
          icon: 'icon-shengjibanbenguanli',
          menuname: '版本管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 112,
              icon: 'icon-shengjibanben',
              menuname: '版本列表',
              hasThird: 'N',
              url: 'version/versionManagement',
              menus: null
            }
          ]
        },
        {
          menuid: 108,
          icon: 'icon-a-14wenjianguanli',
          menuname: '系统设置',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 109,
              icon: 'icon-yinsizhengce',
              menuname: '隐私政策',
              hasThird: 'N',
              url: 'system/privacyPolicy',
              menus: null
            },
            {
              menuid: 110,
              icon: 'icon-xieyi',
              menuname: '注册协议',
              hasThird: 'N',
              url: 'system/registrationAgreement',
              menus: null
            }
          ]
        },
        {
          menuid: 71,
          icon: 'icon-xitongguanli',
          menuname: '系统管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 72,
              icon: 'icon-yonghu',
              menuname: '用户管理',
              hasThird: 'N',
              url: 'system/user',
              menus: null
            },
            // {
            //   menuid: 174,
            //   icon: 'icon-_caidanguanli',
            //   menuname: '菜单管理',
            //   hasThird: 'N',
            //   url: 'system/Module',
            //   menus: null
            // },
            {
              menuid: 73,
              icon: 'icon-yidongyunkongzhitaiicon45',
              menuname: '角色管理',
              hasThird: 'N',
              url: 'system/Role',
              menus: null
            },
          ]
        },
      ],
      msg: 'success'
    }
    this.allmenu = res.data

    // const vm = this
    // let param= {
    //   type: 1,
    // }
    // if(vm.roleInfo && vm.roleInfo.rid){
    //   param.rid = vm.roleInfo.rid
    // }else{
    //   await this.$store.dispatch('getMemberInfo').then((res)=>{
    //     const { code, data = {} } = res
    //     if (code == 0) {
    //       param.rid = data.roleInfo.rid || ''
    //     }
    //   })
    // }
    // vm.apiUrl.menuList(param,'POST')
    //   .then(res => {
    //     const { code , msg,
    //       data: { list = [] }
    //     } = res
    //     if (code == 0) {
    //       this.allmenu = list
    //     } else {
    //       this.$message.error(msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })

    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  /*width: 240px;*/
  width: 200px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #1f2d3d !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 80px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  height: 40px;
}
</style>
